<?php

namespace App\depository;

use App\Models\SubCfgModel;

class SubCfgDep
{
    public $model;

    public function __construct()
    {
        $this->model = new SubCfgModel();
    }

    public function firstByName($teamId,$name){

        $res = $this->model->where('team_id',$teamId)->where('name',$name)->first();
        return $res;

    }
    public function first($id){
        return $this->model->where('id', $id)->first();
    }

    public function list($teamId,$param)
    {
        $res = $this->model->where('team_id',$teamId)->orderBy('id','desc')->get();
        return $res;
    }


    public function add($data)
    {
        $res = $this->model->insertGetId($data);
        return $res;
    }

    public function upd($id, $data)
    {
        $res = $this->model->where('id', $id)->update($data);
        return $res;
    }

    public function del($id)
    {
        $res = $this->model->where('id', $id)->delete();
        return $res;
    }

    public function get_contents($gh_id, $name)
    {
        return $this->model->select('content')->where('team_id', $gh_id)->where('name', $name)->orderBy('id', 'desc')->first();
    }

}
